package com.easyn.CamLinePro;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.easyn.CamLinePro.DateTimePicker.OnDateTimeChangedListener;
import com.easyn.command.TimeInfo;

public class DateTimePickerDialog extends AlertDialog implements
		OnClickListener {
	private static TimeInfo mInfo;
	private DateTimePicker mDateTimePicker;
	private OnDateTimeSetListener mOnDateTimeSetListener;

	@SuppressWarnings("deprecation")
	public DateTimePickerDialog(Context context, TimeInfo date) {
		super(context);
	
		mDateTimePicker = new DateTimePicker(context);
		setView(mDateTimePicker);
		DateTimePickerDialog.mInfo =date;
		/*
		 * 实现接口，实现里面的方法
		 */
		mDateTimePicker
				.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
					@Override
					public void onDateTimeChanged(DateTimePicker view,
							TimeInfo info) {
						DateTimePickerDialog.mInfo = info;
						/**
						 * 更新日期
						 */
						updateTitle(info);
					}
				});

		setButton(context.getString(R.string.btnAdvanced), this);
		setButton2(context.getString(R.string.cancel), (OnClickListener) null);
		// mDate.setTimeInMillis(date);
		updateTitle(date);
	}

	/*
	 * 接口回調控件 秒数
	 */
	public interface OnDateTimeSetListener {
		void OnDateTimeSet(AlertDialog dialog, TimeInfo info);
	}

	/**
	 * 更新对话框日期
	 * 
	 * @param date
	 */
	private void updateTitle(TimeInfo date) {

		setTitle("\t\t\t"+ date.week+ "\t\t\t\t"+date.hour + ":" + date.mimute   );
	}

	/*
	 * 对外公开方法让Activity实现
	 */
	public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
		mOnDateTimeSetListener = callBack;
	}

	public void onClick(DialogInterface arg0, int arg1) {
		if (mOnDateTimeSetListener != null) {
			mOnDateTimeSetListener.OnDateTimeSet(this, mInfo );
		}
	}
}